package com.fk.his.convertor;

import com.alibaba.cola.exception.BizException;
import com.fk.his.domain.model.aggregates.BizNoRule;
import com.fk.his.po.BizNoRulePO;
import com.rickie.dto.data.ErrorCode;
import org.springframework.beans.BeanUtils;

import java.util.Objects;

/**
 * <p>
 * 序号生成规则转换器
 * <p>
 * 示例代码
 * <pre>
 * </pre/>
 *
 * @author InHome
 * @version BME V100R001 2023/03/27
 * @since BME V100R001C40B104
 */
public final class BizNoRuleConvertor {
    /**
     * 把领域模型装换成数据库实体
     *
     * @param bizNoRule 领域模型
     * @return
     */
    public static BizNoRulePO toPO(BizNoRule bizNoRule) {
        if (Objects.isNull(bizNoRule)) {
            throw new BizException(ErrorCode.CARGO_BOOKING_REQUEST_ERROR.getErrCode(), "序号生成规则请求参数错误");
        }
        BizNoRulePO bizNoRulePo = new BizNoRulePO();
        bizNoRulePo.setId(bizNoRule.getId());
        bizNoRulePo.setCurrentNo(bizNoRule.getCurrentNo());
        bizNoRulePo.setDatePattern(bizNoRule.getDatePattern());
        bizNoRulePo.setInitCycle(bizNoRule.getInitCycle());
        bizNoRulePo.setOrgId(bizNoRule.getOrgId());
        bizNoRulePo.setPrefix(bizNoRule.getPrefix());
        bizNoRulePo.setLastTime(bizNoRule.getLastTime());
        bizNoRulePo.setSerialLength(bizNoRule.getSerialLength());
        bizNoRulePo.setRuleCode(bizNoRule.getRuleCode());
        bizNoRulePo.setRuleName(bizNoRule.getRuleName());
        bizNoRulePo.setStep(bizNoRule.getStep());
        bizNoRulePo.setCurrentNo(bizNoRule.getCurrentNo());
        bizNoRulePo.setSuffix(bizNoRule.getSuffix());
        return bizNoRulePo;
    }

    /**
     * 数据库实体转换成领域模型
     *
     * @param bizNoRulePo
     * @return
     */
    public static BizNoRule toDomainObject(BizNoRulePO bizNoRulePo) {
        if (bizNoRulePo == null) {
            return null;
        }
        BizNoRule bizNoRule = new BizNoRule();
        BeanUtils.copyProperties(bizNoRulePo, bizNoRule);
        return bizNoRule;
    }
}
